function str = sptfileheader(varargin)
%SPTFILEHEADER Utility for generating a file header
%   SPTFILEHEADER Generates a file header with no custom annotations for
%   the signal processing toolbox using '%' as the commenting character.
%
%   SPTFILEHEADER(DESC) Generates a file header and adds the description
%   DESC before the toolbox information.  If DESC is less than 10
%   characters it will be on the same line as the toolbox information.
%
%   SPTFILEHEADER(DESC, TBX) Generates a file header for the toolbox
%   specified in the string TBX.
%
%   SPTFILEHEADER(DESC, TBX, COM) Generates a file header using the
%   COM as the commenting character.
%
%   SPTFILEHEADER(DESC, TBX, COM, DATEFORM) Generates a file header using
%   the specified DATEFORM.  See DATESTR for more information.  DATEFORM is
%   0 by default.
%
%   If DESC or TBX is '', the defaults will be used.

%   Author(s): J. Schickler
%   Copyright 1988-2009 The MathWorks, Inc.
%   $Revision: 1.2.4.5 $  $Date: 2009/07/14 04:03:28 $

desc     = '';
tbx      = 'signal';
comment  = '%';
dateform = 0;

if length(varargin) > 0
    if isnumeric(varargin{end})
        dateform      = varargin{end};
        varargin(end) = [];
    end
end
if length(varargin) > 0
    desc = varargin{1};
end
if length(varargin) > 1
    tbx = varargin{2};
end
if length(varargin) > 2,
    comment = varargin{3};
end

% Get the toolbox info which includes the name and version.
minfo = ver('matlab');
tinfo = ver(tbx);
tinfo = tinfo(1); % In case there are multiple toolboxes on the path.

% If the description is short and does not end with a '.' we want to
% attach it to the 'generated by' line.  Otherwise it goes on its own line.
if isempty(desc)
    descStr=desc;
    str1 = sprintf('Generated by MATLAB(R) %s and the %s %s.', ...
        minfo.Version, tinfo.Name, tinfo.Version);
elseif length(desc) < 10 && desc(end) ~= '.',
    descStr = '';
    str1 = sprintf('%s generated by MATLAB(R) %s and the %s %s.',...
        desc, minfo.Version, tinfo.Name, tinfo.Version);
else
    descStr = sprintf(' %s\n%s', desc,comment);
    str1 = sprintf('Generated by MATLAB(R) %s and the %s %s.', ...
        minfo.Version, tinfo.Name, tinfo.Version);
end


% Make sure the "generated on/at/in" makes sense.
switch dateform
    case {3, 4, 5, 10, 11, 12, 17, 18, 27, 28}
        str2 = sprintf('%s\n%s Generated in: %s\n%s', comment, comment, ...
            datestr(now, dateform), comment);
    case {13, 14, 15, 16}
        str2 = sprintf('%s\n%s Generated at: %s\n%s', comment, comment, ...
            datestr(now, dateform), comment);
    otherwise
        str2 = sprintf('%s\n%s Generated on: %s\n%s', comment, comment, ...
            datestr(now, dateform), comment);
end

str = sprintf('%s\n%s%s %s\n%s', comment, comment, descStr, str1, str2);

% [EOF]
